package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Consumption;
import cn.wolfcode.domain.ConsumptionKey;
import cn.wolfcode.mapper.ConsumptionMapper;
import cn.wolfcode.query.ConsumptionQueryObject;
import cn.wolfcode.service.IConsumptionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ConsumptionService implements IConsumptionService {

    @Autowired
    private ConsumptionMapper consumptionMapper;


    @Override
    public int deleteByPrimaryKey(Long id) {
        return consumptionMapper.deleteByPrimaryKey(new ConsumptionKey(id));
    }

    @Override
    public int insert(Consumption record) {
        return consumptionMapper.insert(record);
    }

    @Override
    public Consumption selectByPrimaryKey(Long id) {
        return consumptionMapper.selectByPrimaryKey(new ConsumptionKey(id));
    }

    @Override
    public List<Consumption> selectAll() {
        return consumptionMapper.selectAll();
    }

    @Override
    public int updateByPrimaryKey(Consumption record) {
        return consumptionMapper.updateByPrimaryKey(record);
    }

    @Override
    public PageInfo<Consumption> list(ConsumptionQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),"id asc");
        List<Consumption> list = consumptionMapper.selectForList(qo);
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }

    @Override
    public Consumption selectByCno(String cno) {
        return consumptionMapper.selectByCno(cno);
    }
}
